﻿<template>
  <div class="busAddress-container">
    <el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="用户账户">
          <el-input v-model="queryParams.loginName" clearable="" placeholder="请输入用户账户"/>
          
        </el-form-item>
        <el-form-item label="收货人">
          <el-input v-model="queryParams.conSignee" clearable="" placeholder="请输入收货人"/>
          
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="queryParams.phone" clearable="" placeholder="请输入电话"/>
          
        </el-form-item>
        <el-form-item label="省">
           <el-select v-model="queryParams.province" filterable placeholder="请输入省" @change="getCity">
                <el-option value="">无</el-option>
                <el-option v-for="dict in provinceList" :key="dict.id" :value="dict.name" :label="dict.name">
                  {{ dict.name }}
                </el-option>
              </el-select>
          <!-- <el-input v-model="queryParams.province" clearable="" placeholder="请输入省"/> -->
          
        </el-form-item>
        <el-form-item label="市">
          <el-select v-model="queryParams.city" filterable placeholder="请输入市"  @change="getArea">
                <el-option value="">无</el-option>
                <el-option v-for="dict in cityList" :key="dict.id" :value="dict.name" :label="dict.name">
                  {{ dict.name }}
                </el-option>
              </el-select>
          <!-- <el-input v-model="queryParams.city" clearable="" placeholder="请输入市"/> -->
          
        </el-form-item>
        <el-form-item label="区">
          <el-select v-model="queryParams.area" filterable placeholder="请输入区">
                <el-option value="">无</el-option>
                <el-option v-for="dict in areaList" :key="dict.id" :value="dict.name" :label="dict.name">
                  {{ dict.name }}
                </el-option>
              </el-select>
          <!-- <el-input v-model="queryParams.area" clearable="" placeholder="请输入区"/> -->
          
        </el-form-item>
        <el-form-item label="详细地址">
          <el-input v-model="queryParams.address" clearable="" placeholder="请输入详细地址"/>
          
        </el-form-item>
        <el-form-item label="是否默认收货地址">
          <el-input-number v-model="queryParams.isDefault"  clearable="" placeholder="请输入是否默认收货地址"/>
          
        </el-form-item>
        <el-form-item label="是否有效数据">
          <el-input-number v-model="queryParams.isEnable"  clearable="" placeholder="请输入是否有效数据"/>
          
        </el-form-item>
        <el-form-item>
          <el-button-group>
            <el-button type="primary"  icon="ele-Search" @click="handleQuery" v-auth="'busAddress:page'"> 查询 </el-button>
            <el-button icon="ele-Refresh" @click="() => queryParams = {}"> 重置 </el-button>
            
          </el-button-group>
          
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="ele-Plus" @click="openAddBusAddress" v-auth="'busAddress:add'"> 新增 </el-button>
          
        </el-form-item>
        
      </el-form>
    </el-card>
    <el-card class="full-table" shadow="hover" style="margin-top: 8px">
      <el-table
				:data="tableData"
				style="width: 100%"
				v-loading="loading"
				tooltip-effect="light"
				row-key="id"
				border="">
        <el-table-column type="index" label="序号"   width="55" align="center"/>
        <el-table-column prop="id" label="主键Id"   show-overflow-tooltip="" />
         <el-table-column prop="loginName" label="用户账户"   show-overflow-tooltip="" />
         <el-table-column prop="conSignee" label="收货人"   show-overflow-tooltip="" />
         <el-table-column prop="phone" label="电话"   show-overflow-tooltip="" />
         <el-table-column prop="province" label="省"   show-overflow-tooltip="" />
         <el-table-column prop="city" label="市"   show-overflow-tooltip="" />
         <el-table-column prop="area" label="区"   show-overflow-tooltip="" />
         <!-- <el-table-column prop="provinceName" label="省"   show-overflow-tooltip="" />
         <el-table-column prop="cityName" label="市"   show-overflow-tooltip="" />
         <el-table-column prop="areaName" label="区"   show-overflow-tooltip="" /> -->
         <el-table-column prop="address" label="详细地址"   show-overflow-tooltip="" />
         <el-table-column prop="isDefault" label="是否默认收货地址"   show-overflow-tooltip="" />
         <el-table-column prop="isEnable" label="是否有效数据"   show-overflow-tooltip="" />
         <el-table-column prop="createUserName" label="创建者"   show-overflow-tooltip="" />
        <el-table-column prop="updateUserName" label="修改者" show-overflow-tooltip=""/>
        <el-table-column label="操作" width="200" align="center" fixed="right" show-overflow-tooltip="" v-if="auth('busAddress:edit') || auth('busAddress:delete')">
          <template #default="scope">
            <el-button icon="ele-Edit" size="small" text="" type="primary" @click="openEditBusAddress(scope.row)" v-auth="'busAddress:edit'"> 编辑 </el-button>
            <el-button icon="ele-Delete" size="small" text="" type="primary" @click="delBusAddress(scope.row)" v-auth="'busAddress:delete'"> 停用 </el-button>
            <el-button icon="ele-Check" size="small" text="" type="primary" @click="isEnable(scope.row)" v-auth="'busAddress:page'"> 启用 </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
				v-model:currentPage="tableParams.page"
				v-model:page-size="tableParams.pageSize"
				:total="tableParams.total"
				:page-sizes="[10, 20, 50, 100]"
				small=""
				background=""
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				layout="total, sizes, prev, pager, next, jumper"
	/>
      <editDialog
			    ref="editDialogRef"
			    :title="editBusAddressTitle"
			    @reloadTable="handleQuery"
      />
    </el-card>
  </div>
</template>

<script lang="ts" setup="" name="busAddress">
  import { ref } from "vue";
  import { ElMessageBox, ElMessage } from "element-plus";
  import { auth } from '/@/utils/authFunction';
  //import { formatDate } from '/@/utils/formatTime';

  import editDialog from '/@/views/main/busAddress/component/editDialog.vue';
  import { pageBusAddress, deleteBusAddress,setEnable } from '/@/api/main/busAddress';
  import { getSysRegionList,getProvinceList,getCityList,getAreaList}  from '/@/api/main/sysCity';



    const editDialogRef = ref();
    const loading = ref(false);
    const tableData = ref<any>
      ([]);
      const queryParams = ref<any>
        ({});
        const tableParams = ref({
        page: 1,
        pageSize: 10,
        total: 0,
        });
        const editBusAddressTitle = ref("");
        const getCity=async (val:any)=>{
              const res= await getCityList({id:val})
              cityList.value=res.data.result;
        }
        const getArea=async (val:any)=>{
              const res= await getAreaList({id:val})
              areaList.value=res.data.result;
        }

        // 查询操作
        const handleQuery = async () => {
        loading.value = true;
        var res = await pageBusAddress(Object.assign(queryParams.value, tableParams.value));
        tableData.value = res.data.result?.items ?? [];
        tableParams.value.total = res.data.result?.total;
        loading.value = false;
        };

        // 打开新增页面
        const openAddBusAddress = () => {
        editBusAddressTitle.value = '添加收货信息管理';
        editDialogRef.value.openDialog({});
        };

        // 打开编辑页面
        const openEditBusAddress = (row: any) => {
        editBusAddressTitle.value = '编辑收货信息管理';
        editDialogRef.value.openDialog(row);
        };

        // 停用
        const delBusAddress = (row: any) => {
        ElMessageBox.confirm(`确定要停用吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        })
        .then(async () => {
        await deleteBusAddress(row);
        handleQuery();
        ElMessage.success("停用成功");
        })
        .catch(() => {});
        };
        // 启用
        const isEnable = async(row: any) => {
         
         await setEnable(row);
         handleQuery();
         ElMessage.success("启用成功");
        
         };

        // 改变页面容量
        const handleSizeChange = (val: number) => {
        tableParams.value.pageSize = val;
        handleQuery();
        };

        // 改变页码序号
        const handleCurrentChange = (val: number) => {
        tableParams.value.page = val;
        handleQuery();
        };

        // 初始化
     
        const sysRegionList = ref<any>([]);
        const provinceList = ref<any>([]);
        const cityList = ref<any>([]);
        const areaList = ref<any>([]);
        const Init = async () => {
        //初始化-行政区划
        
        await getSysRegionList().then(res => {
          if(res.data.code==200) {
            for(var i=0; i<res.data.result.length; i++) {
              var ele = {
                id: res.data.result[i].id,
                name: res.data.result[i].name
              };
              sysRegionList.value.push(ele);
            }
          }
        });
        await getProvinceList().then(res => {
          if(res.data.code==200) {
            for(var i=0; i<res.data.result.length; i++) {
              var ele = {
                id: res.data.result[i].id,
                name: res.data.result[i].name
              };
              provinceList.value.push(ele);

            }
          }
        });
        // await getCityList().then(res => {
        //   if(res.data.code==200) {
        //     for(var i=0; i<res.data.result.length; i++) {
        //       var ele = {
        //         id: res.data.result[i].id,
        //         name: res.data.result[i].name
        //       };
        //       cityList.value.push(ele);

        //     }
        //   }
        // });
        // await getAreaList().then(res => {
        //   if(res.data.code==200) {
        //     for(var i=0; i<res.data.result.length; i++) {
        //       var ele = {
        //         id: res.data.result[i].id,
        //         name: res.data.result[i].name
        //       };
        //       areaList.value.push(ele);
        //     }
        //   }
        // });

      
};




handleQuery();
Init();
</script>


